package com.hua.controller;

import com.hua.common.Response;
import com.hua.domain.Discountcard;
import com.hua.service.impl.DiscountcardServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName:DiscountController
 * Package:com.hua.controller
 * Description:
 *
 * @data: 2022/10/22 15:57
 * @author:ChenJH
 */
@RestController
@Api("优惠卷接口")
@RequestMapping("/discount")
public class DiscountController {

    @Resource
    private DiscountcardServiceImpl discountcardServiceImpl;

    @GetMapping("/getAllDiscounts")
    @ApiOperation("用户获取所有优惠卷")
    public Response<List<Discountcard>>  getAllDiscounts(Long userId) {
        return discountcardServiceImpl.getAllDiscounts(userId);
    }

    @PostMapping("/sendDiscount/{discountId}")
    @ApiOperation("商家发送优惠卷")
    public Response<String>sendDiscount(@PathVariable(value = "discountId") Long discountId) {
        return discountcardServiceImpl.sendDiscount(discountId);
    }

    @PostMapping("/createDiscount")
    @ApiOperation("添加一张优惠卷")
    public Response<String> createDiscount(@RequestBody Discountcard discountcard){
        return discountcardServiceImpl.createDiscount(discountcard);
    }

    @PostMapping("/deleteDiscount/{discountcardId}")
    @ApiOperation("删除一张优惠卷")
    public Response<String> deleteDiscount(@PathVariable(value = "discountcardId") Integer discountcardId){
        return discountcardServiceImpl.deleteDiscount(discountcardId);
    }

    @PutMapping("/updateDiscount")
    @ApiOperation("修改一张优惠卷")
    public Response<String> updateDiscount(@RequestBody Discountcard discountcard){
        return discountcardServiceImpl.updateDiscount(discountcard);
    }

    @PutMapping("/updateDiscountStatus/{discountId}/{status}")
    @ApiOperation("修改一张优惠卷状态")
    public Response<String> updateDiscount(@PathVariable(value = "discountId") Long discountId,
                                           @PathVariable(value = "status") Integer status){
        return discountcardServiceImpl.updateDiscountStatus(discountId, status);
    }

}
